//房源panal
Ext.define('customer.subscribe.view.estatePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		var row_1={
				id:"isPaydepositTrue",
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
			    border: false,
				layout: 'hbox',
				items: [{
		            items: [{
		            	xtype:'container',
		            	layout:'hbox',
		            	border:true,
		            	items:[{
		            		xtype:'displayfield',
			                fieldLabel: '房号',
			                name: 'combinedName'
			                }]
		                
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '建筑面积(㎡)',
		                anchor: '80%',
		                name: 'buildingArea'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '分摊面积(㎡)',
		                anchor: '80%',
		                name: 'sharingArea'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '折前单价(元)',
		                anchor: '80%',
		                name: 'unitPrice',
		                readOnly:true
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '房源状态',
		                anchor: '80%',
		                name: 'roomStatusName'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '套内面积(㎡)',
		                anchor: '80%',
		                name: 'innerArea'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '计价面积(㎡)',
		                anchor: '80%',
		                name: 'calculateArea'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '折前总价(元)',
		                anchor: '80%',
		                name: 'totalPrice'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
				id:'estatePanel',
				title:"房产信息",
				bodyStyle: 'padding:5px 5px 0',
		        minHeight: 200,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

var oldSubscribeForm = Ext.create("Ext.form.FormPanel", {
	autoWidth: true,
	autoHeight: true,
	title:"原认购信息",
	fieldDefaults: {
        labelWidth: 120,
        labelAlign: "right",
        margin: "0 0 10 0"
    },
	items: [
		{
			xtype: "fieldcontainer", layout: "hbox",
			items: [
				{xtype: "displayfield", name: "customerName", fieldLabel: "客户姓名", width: 400},
				{xtype: "displayfield", name: "receivedPayAmount", fieldLabel: "已收金额", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')}
			]
		},
		{xtype: "displayfield", name: "checkDateStr", fieldLabel: "业务日期", width: 400,
	    	renderer : function(val) {
				
				return val;
			}
		},
		{
			xtype: "fieldcontainer", layout: "hbox",
			items: [
				{xtype: "displayfield", name: "comboxRoomName", fieldLabel: "原楼盘名称及房号", width: 400},
				{xtype: "displayfield", name: "calculateArea", fieldLabel: "原计价面积", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')}
			]
		},
		{
			xtype: "fieldcontainer", layout: "hbox",
			items: [
				{xtype: "displayfield", name: "conversionPrice", fieldLabel: "原房屋单价", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')},
				{xtype: "displayfield", name: "lumpsumPrice", fieldLabel: "原折前总价", width: 400, renderer: Ext.util.Format.numberRenderer('0,000.00')}
			]
		}
	]
});

oldSubscribeForm.getForm().load({
    url: contextPath + '/marketing/businessAbnorma/subscribeChangeRoomById',
    params: {"id": oldSubId},
    success: function(form, action){
    	console.log(form);
	},
    failure: function(form, action) {
    	 Ext.Msg.alert('提示', '加载数据失败!');
	}
});

Ext.define('customer.subscribe.view.customerPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		var row_1={
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		            	xtype:'container',
		            	layout:'hbox',
		            	anchor: '80%',
		            	items:[{
		            		xtype:'displayfield',
			                fieldLabel: '客户姓名',
			                anchor: '80%',
			                name: 'customerName'
			                }]
		                
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '证件类型',
		                anchor: '80%',
		                name: 'peDocumentTypeName'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '证件号码',
		                anchor: '80%',
		                name: 'peDocumentNumber'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '联系电话',
		                anchor: '80%',
		                name: 'customerPhone'
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '邮寄地址',
		                anchor: '80%',
		                name: 'peContactAddress'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '邮编',
		                anchor: '80%',
		                name: 'pePostcode'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '客户来源',
		                anchor: '80%',
		                name: 'customerOriginName'
		            }]
		        }]
	    };
		var documentTypeStore = Ext.create('Ext.data.Store', {
		    fields: ['value', 'name'],
		    data :documentType
		});
		var gridStore = Ext.create('Ext.data.Store', {
			id:'familyMemberGridStore',
		    fields: ["memberName","documentType","documentNumber","mobile"],
		    //是否在服务端排序 （true的话，在客户端就不能排序）
		    remoteSort: false,
		    proxy: {
		        type: 'ajax',
		        url: contextPath+'/customer/familyMember/findList',
		        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		            type: 'json', //返回数据类型为json格式
		            root: 'obj'
		        },
		        actionMethods: {read: 'POST'},
	            extraParams:{
	            	buyId:subscribeId,
	            	memberType:'3'
	            }
		    },
		    autoLoad:true
		});
		var columns = [{
			text : "姓名",
			dataIndex : 'memberName',
			width:'25%'
		}, {
			text : "证件类型",
			dataIndex : 'documentType',
			width:'25%',
            renderer: function(value,metadata,record){  
                var index = documentTypeStore.find('value',value);  
                if(index!=-1){  
                    return documentTypeStore.getAt(index).data.name;  
                }  
                return value;  
            }
		}, {
			text : "证件号码",
			dataIndex : 'documentNumber',
			width:'25%'
		},{
			text : "手机号码",
			dataIndex : 'mobile',
			width:'20%'
		}];
		var row_2=Ext.create('Ext.grid.Panel', {
			id:'familyMemberGridPanel',
			region : 'south',
			title:"共同购房者",
			minHeight:200,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore,
			columns : columns
		});
		var items=[row_1,row_2];
		var initConfigg = {
				id:'customerPanel',
		        title:"客户信息",
		        minHeight:320,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.subscribe.view.subscribePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '折前单价(元)',
		                name:'conversionPrice'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '认购编号',
		                name:'subscribeCode'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '签约单价(元)',
		                name: 'subscribePrice'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '业务状态',
		                name:'businessStatus',
		                renderer : function(val) {
		                	if (val == 1) {
		                        return '认购';
		                    } else if (val == 3) {
		                        return '已换房';
		                    }else if (val == 2) {
		                        return '认购转签约';
		                    }else if (val == 4) {
		                        return '已更名';
		                    }else if (val == 5) {
		                        return '退认购';
		                    }
		                    return val;
		                }
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '折前总价(元)',
		                name: 'lumpsumPrice'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '认购转签约日期',
		                name:'conversionSignDate',
		                renderer:function(val){
		                	if(val==null||val==""){
		                		return "";
		                	}
		                	return Ext.Date.format(new Date(val),'Y-m-d');
		                }
		            },{
		            	xtype: 'displayfield',
		                fieldLabel: '合同金额(元)',
		                name:'subscribeAmount',
		                readOnly:true,
		            }]
		        }]
	    };
		var row_2={
				fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side'
		        },
		        collapsible: true,
		        //collapsed: true,
				xtype: 'fieldset',
                title:'折扣信息',
                //layout: 'anchor',
                defaultType: 'displayfield',
                items:[
                {
                    	xtype: 'displayfield',
                    	fieldLabel: '折后总价(元)',
                        name: 'discountAfterPrice',
                        id:'discountAfterPrice'
                	
                },{
                	xtype: 'displayfield',
                	fieldLabel: '折扣金额(元)',
                    name: 'discountAmount'
                },{
	            	xtype:'container',
	            	layout:'hbox',
	            	anchor: '80%',
	            	items:[{
	            		xtype: 'displayfield',
		                fieldLabel:'折扣比例(%)',
		                name:'discountRate'
	            	}]
	                
	            },{
                	xtype: 'displayfield',
                	fieldLabel: '折扣说明',
                	anchor: '50%',
                    name: 'discountNote'
                }]
	    };
		var dealCategoryStore = Ext.create('Ext.data.Store', {
		    fields: ['value', 'text'],
		    data : [
                {"value":"1", "text":"推荐成交"},
		        {"value":"2", "text":"单独成交"},
		        {"value":"3", "text":"共同成交"}
		    ]
		});
		var items=[row_1,row_2,,{
        	xtype: 'displayfield',
            fieldLabel: '应收认购金(元)',
            name:'depositReceivable'
        },{
        	xtype: 'displayfield',
            fieldLabel: '已收认购金(元)',
            name:'alsubscribeAmount'
        },{
         	xtype: 'displayfield',
            fieldLabel: '已收认筹金(元)',
            name:'receivedPayAmount'
        },{
        	xtype: 'displayfield',
            fieldLabel: '认购日期',
            name:'subscribeDate',
            renderer:function(val){
            	if(val==null||val==""){
            		return "";
            	}
            	return Ext.Date.format(new Date(val),'Y-m-d');
            }
        },{
        	xtype: 'displayfield',
            fieldLabel: '成交类别',
            name:'dealCategory',
            renderer:function(value){
            	if(value=="1"){
        			Ext.getCmp("referenceName").show();
        			//Ext.getCmp("referenceProportion").show();
            		return "推荐成交";
            	}else if(value=="2"){
            		return "单独成交";
            	}else if(value=="3"){
            		return "共同成交";
            	}
            	return "";
            }
        },
            		{xtype:"displayfield", name:"referenceId", hidden:true},
            		{xtype:"displayfield", id:'referenceName', fieldLabel:'推荐人姓名', hidden:true, name:"referenceName"},
            		{xtype:"displayfield", id:'referenceProportion', fieldLabel:'推荐人比例', hidden:true, name:"referenceProportion",maxLength:3,regex:/^[1-9]\d*$/}
        ,{
        	xtype: 'displayfield',
            fieldLabel: '经纪人',
            name:'currentUserName',
            value:userName
        },{
        	xtype: 'displayfield',
            fieldLabel: '换房原因',
            anchor: '50%',
            name:'remark'
        }];
		var initConfigg = {
				id:"subscribeInfoForm",
		        title:"认购信息",
		        minHeight:200,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

function vaildResult(url){
	   Ext.Ajax.request({
   	    url: contextPath+'/marketing/room/vaildNeedReceive',
   	    params: {
   	    	subId: subscribeId
   	    },
   	    method: 'POST',
   	    success: function(response){
   	        var text = Ext.decode(response.responseText);
   	        if(text.result=="1"){
   	        	Ext.Msg.alert('提示', text.msg);
   	        }else if(text.result=="0"){
   	          var tabKey = "sub_to_sig_"+subscribeId;
		      parent.openMenu("0",tabKey,"","认购转签约",url);
   	        }
   	    }
   	});
}
Ext.define('customer.subscribe.viewPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var estatePanel= Ext.create("customer.subscribe.view.estatePanel");
		var customerPanel= Ext.create("customer.subscribe.view.customerPanel");
		var payDepositPanel= Ext.create("customer.subscribe.view.subscribePanel");
		//审批历史
		 var selectWindow=Ext.create('component.proces.history',{
			 processInstanceId: procInstId,
			 contextPath:contextPath
	 	 });
		 //未提交状态，无审核记录，不显示
		 if("0" == auditStatus){
			 selectWindow = null;
		 }
		 
		 var fileAttachment = Ext.create('component.file.attachment',{
		    objectId: subscribeId,
		    imageType: "2",
		    contextPath:contextPath
		});
		 
		 var busWindow;
		 if(busProcInstId!=null&&busProcInstId!=""){
			busWindow=Ext.create('component.proces.approval',{
				 processInstanceId: busProcInstId
		 	 });
		}
		var defaultConfigg = {
				buttonAlign:'center',
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
		        renderTo:Ext.getBody(),
				items:[oldSubscribeForm,estatePanel,customerPanel,payDepositPanel,selectWindow,busWindow, fileAttachment]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
	}
});


